package fr.gest4team.app.pilotage.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

import fr.gest4team.app.pilotage.dao.abstrait.AbstractTacheDao;
import fr.gest4team.app.pilotage.dao.interfaces.ITacheDao;
import fr.gest4team.app.pilotage.dto.Tache;

/**
 * Dao modifiable
 * 
 * @see fr.gest4team.app.pilotage.dto.Tache
 */
public class TacheDao extends AbstractTacheDao implements ITacheDao {

    /**
     * @author brug
     * @return retourne la liste des Taches.
     */
    public List<Tache> chargerListeTache() {
        final DetachedCriteria criteria = DetachedCriteria.forClass(Tache.class);
        return executeDetachedCriteria(criteria);
    }

    public Tache findByCode(final String code) {
        final String hql = "from Tache as a where a.code=?";
        final List<Tache> list = executeHqlQuery(hql, new Object[] { code });
        return (list.size() == 1) ? list.get(0) : null;
    }

    public void delete(final String code) {
        final String hql = "delete Tache as a where a.code=?";
        getHibernateTemplate().bulkUpdate(hql, code);
    }

    public void deleteVersion(final Integer id) {
        final String hql = "update Tache as t set t.version=null where t.version=?";
        getHibernateTemplate().bulkUpdate(hql, id);
    }

    public List<Tache> chargerListeTache(final String version) {
        final String hql = "from Tache as a where a.code=?";
        return executeHqlQuery(hql, new Object[] { version });
    }
}